package com.qingcheng.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.qingcheng.dao.SeckillGoodsMapper;
import com.qingcheng.pojo.seckill.SeckillGoods;
import com.qingcheng.pojo.seckill.SeckillOrder;
import com.qingcheng.pojo.seckill.SeckillStatus;
import com.qingcheng.service.seckill.SeckillOrderService;
import com.qingcheng.task.MultiThreadingCreateOrder;
import com.qingcheng.utils.IdWorker;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;

import java.util.Date;

@Service
public class SeckillOrderServiceImpl implements SeckillOrderService {

    @Autowired
    private RedisTemplate redisTemplate;
    @Autowired
    private MultiThreadingCreateOrder multiThreadingCreateOrder;

    /**
     * 抢单
     * @param id 商品id
     * @param time 当前时间字符串
     * @param userName //用户
     * @return
     */
    @Override
    public Boolean add(Long id, String time, String userName) {
        //排队信息封装
        SeckillStatus seckillStatus = new SeckillStatus(userName,new Date(),1,id,time);

        redisTemplate.boundListOps("SeckillOrderQueue").leftPush(seckillStatus);

        multiThreadingCreateOrder.createOrder();
        return true;
    }
}
